package com.cxrj.zhsq.personnelManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.personnelManage.entity.PropertyPersonnel;
import com.cxrj.zhsq.personnelManage.service.PropertyPersonnelService;

@RestController
public class PropertyPersonnelController {

	@Resource
	private PropertyPersonnelService propertyPersonnelService;

	/**
	 * 分页查询服务人员
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyPersonnels", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectPropertyPersonnels(HttpServletRequest request, HttpServletResponse response) {
		return propertyPersonnelService.seletePropertyPersonnelPage(request, response);
	}

	/**
	 * 根据id查询服务人员
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyPersonnelById", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyPersonnelById(String id, HttpServletRequest request) {
		return propertyPersonnelService.selectPropertyPersonnelById(id);
	}

	/**
	 * 添加服务人员
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyPersonnel", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyPersonnel(PropertyPersonnel propertyPersonnel, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyPersonnel.setCommunityId(request.getSession().getAttribute("communityId").toString());
			resultMap = propertyPersonnelService.insertPropertyPersonnel(propertyPersonnel);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改服务人员
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyPersonnel", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyPersonnel(PropertyPersonnel propertyPersonnel, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = propertyPersonnelService.updatePropertyPersonnel(propertyPersonnel);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	
	/**
	 * 查询全部服务人员
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyPersonnelByAll", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyPersonnelByAll(HttpServletRequest request) {
		return propertyPersonnelService.selectPropertyPersonnelByAll(request);
	}
}
